package com.gmscosmo.janus.util;

import java.util.Collection;
import java.util.Map;
import java.util.UUID;

/**
 *
 * ClassName: Utils
 * Description: 
 * Date: 2021/3/10 10:33 
 * @author stephen.qiu
 * @version 1.0
 *
 */
public class Utils {
	private final static String NULL = "null";

	public static boolean isEmpty(Object obj) {
		if (obj == null) {
			return true;
		} else {
			if (obj instanceof String) {
				String instance = (String) obj;
				if (instance.trim().length() <= 0 || NULL.equalsIgnoreCase(instance)) {
					return true;
				}
			} else if (obj instanceof Integer) {
				Integer instance = (Integer) obj;
				if (instance < 0) {
					return true;
				}
			} else if (obj instanceof Collection) {
				Collection<?> instance = (Collection) obj;
				if (instance.size() <= 0) {
					return true;
				}
			} else if (obj instanceof Map) {
				Map<?, ?> instance = (Map) obj;
				if (instance.size() <= 0) {
					return true;
				}
			} else if (obj instanceof Object[]) {
				Object[] instance = (Object[]) ((Object[]) obj);
				if (instance.length <= 0) {
					return true;
				}
			} else if (obj instanceof Long) {
				Long instance = (Long) obj;
				if (instance < 0L) {
					return true;
				}
			}
			return false;
		}
	}

	public static boolean isNotEmpty(Object obj) {
		return !isEmpty(obj);
	}

	/**
	 * 统一生成UUID
	 * 去除 ”-“
	 * 长度 32位
	 *
	 * @return
	 */
	public static String generateUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}
}